/**
 * @desc: 点击删除收件箱信息
 * 
 * @time: 2012-06-26
 * @autor: jack
**/
$(".sendmsg").click(function(){
	var msgid = $(this).attr("data-id");
	var cate  = $(this).attr("cate");
	$.fn.confirm({
		msg:'确定删除这条信息？',
		callback:function(){
			$.ajax({
				type:"post",
				url:"/?uajax/ajaxdelmessage",
				data:"msgid="+msgid+"&cate="+cate,
				dataType:"json",
				async: false,
				success: function(msg)
				{
					if(msg.data == 'NoLogin')
					{
						logindialog();
					}else if(msg.data == 'OK')
					{
						$(this).parent().remove();
						window.location.reload();
					}else
					{
						showerrorinfo('操作错误', '删除失败，请重试！');
					}
				}
			})
		}
	})
})

/**
 * @desc: 收件箱全选/取消
**/
$(".czl").live("click", function(){
	var czlval = $(this).attr("value");
	if(czlval == 0)
	{
		$('[name="msgid[]"]').attr("checked",true);
		$(this).attr("value", 1);
	}else
	{
		$('[name="msgid[]"]').attr("checked",false);
		$(this).attr("value", 0);
	}
})

/**
 * @desc: 批量删除收件箱选中信息
**/
$(".sendmsgbtn").click(function(){
	var megobjs	= $('[name="msgid[]"]:checked');
	var cate = $(this).attr("id");
	if(megobjs.size() > 0)
	{
		//var msgids	= '';
		var msgids	= new Array();
		megobjs.each(function(k,v)
		{
			//msgids	+= '&msgid[]='+$(v).val();
			msgids[k]	= $(v).val();
		})
		$.fn.confirm({
			msg:'确定删除所有选中信息？',
			callback:function(){
				$.ajax({
					type:"post",
					url:"/?uajax/ajaxbatdelmessage",
					data:"msgids="+msgids+"&cate="+cate,
					dataType:"json",
					async: false,
					success: function(msg)
					{
						if(msg.data == 'NoLogin')
						{
							logindialog();
						}else if(msg.data == 'OK')
						{
							$(this).parent().remove();
							window.location.reload();
						}else
						{
							showerrorinfo('操作错误', '删除失败，请重试！');
						}
					}
				})
			}
		})
	}
})

/**
 * @desc: 删除写新消息页面已选中的用户名
**/
$(".ic_lcox").live("click", function(){
	$(this).parent().remove();
    //提示“必填”内容
    if($(".nambox > .namsh").html() == null)
    {
        $("#sendusername").attr('value',"请从右侧好友列表中选择");
    }
})

/**
 * @desc: 写新消息发送消息
**/
$(".friendselecter").click(function(){
    $(".namepoint").remove();//删除提示内容
    $("#sendusername").attr('value','');//添加时删除提示“必填”字符串
	var friendid = $(this).attr("friendid");
	var friendname = $(this).attr("friendname");
	var html = '<span class="namsh">'+friendname+' <a href="javascript:void(0);" class="ic_lcox"></a><input type="hidden" name="fids[]" value="'+friendid+'" /></span>';
	var friendstr = $(".namsh").length;
	if(friendstr > 4)
	{
		showerrorinfo('温馨提示', '添加的人数已经达到上限！');
	}else
	{
		if(friendstr > 0)
		{
			for(var i = 0; i < friendstr; i++)
	        {
				var addfid = $(".namsh").find("input").eq(i).val();
				if(friendid == addfid)
				{
					showerrorinfo('温馨提示', '不能重复添加！');
					return false;
				}
	        }
		}
		$(".naput").before(html);
	}
})

/**
 * @desc: 删除提醒信息
 * @param: int $notice_id
**/
$(".delremind").click(function(){
	var notice_id = $(this).attr("data-id");
	var cates = $(this).attr("cate")
	var data = "noticeid="+notice_id+"&cate="+cates;
	var string = cates == 'one' ? '确定删除这条提醒信息？' : '确定删除所有提醒信息？';
	$.fn.confirm({
		msg:string,
		callback:function(){
			$.ajax({
				type:"post",
				url:"/uajax/delremind",
				data:data,
				dataType:"json",
				async: true,
				success: function(msg)
				{
					if(msg.data.info == 'NoLogin')
					{
						logindialog();
					}else if(msg.data.info == 'OK')
					{
						$(this).parent().remove();
						window.location.reload();
					}else
					{
						showerrorinfo('操作错误', '删除失败，请重试！');
					}
				}
			})
		}
	})
})


function settitle()
{ 
    $(".titlepoint").remove();
    if($("#title").val() == "必填")
    {
        $("#title").attr('value','');  
    }
    
}
function checktitle() 
{                             
    if($("#title").val() == "") 
    {
        $("#title").attr('value',"必填");
    }    
}
function setcontent() {
    $(".contentpoint").remove();
    if($(".scotext").val() == "必填")
    {
        $(".scotext").val('');
    }    
}
function checkcontent()
{ 
    if($(".scotext").val() == "") 
    {
        $(".scotext").val("必填");
    }                               
}
$("#submit").click(function(){
   var namshhtml = $(".namsh").html();
   var title = $("#title").val();
   var content = $(".scotext").val();
   var namepoint = "";
   var titlepoint = "";
   var contentpoint = "";
   if(namshhtml == null)
   {
       namepoint = "收件人不能为空";
       $(".namepoint").remove();
       var html = "<div class='namepoint'><span class='mlm sewrong'>"+namepoint+"</span></div>";
       $(".nambox").after(html);
   }
   if(title == "必填" || title == "")
   {
       titlepoint = "主题不能为空";
       $(".titlepoint").remove();
       var html = "<div class='titlepoint'><span class='mlm sewrong'>"+titlepoint+"</span></div>";
       $("#title").parent(".iput").after(html);
   }
   if(content == "必填" || content == "")
   {
       contentpoint = "内容不能为空";
       $(".contentpoint").remove();
       var html = "<div class='contentpoint'><span class='mlm sewrong'>"+contentpoint+"</span></div>";
       $(".scotext").parent(".iput").after(html);
   }
   if(namepoint != "" || titlepoint != "" || contentpoint != "")
   {         
        return false; 
   }
    
});